﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebApi4000.Domain
{
    public class DbInitializeHelper
    {
        public static void Initillzer()
        {
            using (var db = new Admin4000())
            {
                var dbExist= db.Database.EnsureCreated();

                var tempBrand = db.Brands.Any();

                if (!tempBrand)
                {
                    var brand = new Brand
                    {
                        BrandName = "华为",
                        Description = "目前买不起的牌子"
                    };
                    db.Brands.Add(brand);
                    db.SaveChanges();

                    db.Products.AddRange(new Product[]
                    {
                    new Product
                    {
                        ProductName="Huawei not 21 白色",
                        ShortDesc="Huawei not 21的描述",
                        FullDesc="Huawei not 21详情",
                        BrandId=brand.Id
                    },
                    new Product
                    {
                        ProductName="Huawei not 22 银色",
                        ShortDesc="Huawei not 22的描述",
                        FullDesc="Huawei not 22详情",
                        BrandId=brand.Id
                    }
                    });
                    db.SaveChanges();
                }
                
            }
        }
    }
}
